#include <iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int a[10];
    int temp;
    for(int i = 0; i < N; i++)
    {
        cin >> temp;
        a[i] = temp;
    }
   
    int min = a[0];
    int minIndex = 0;
    for(int i = 0; i<N; i++)
    {
        if(a[i] < min)
        {
            min = a[i];
            minIndex = i;
        }
    }
    temp = a[0];
    a[0] = a[minIndex];
    a[minIndex] = temp;

    int max= a[0];
    int maxIndex = 0;
    for(int i = 0; i<N; i++)
    {
        if(a[i] > max)
        {
            max = a[i];
            maxIndex = i;
        }
    }
    temp = a[N -1];
    a[N -1] = a[maxIndex];
    a[maxIndex] = temp;

    for(int i = 0 ; i<N; i++) 
        cout<<a[i]<<" ";
}